import os


# 1 删除指定文件夹下面的所有文件
def del_dir(file_path):
    filenames = os.listdir(file_path)
    for filename in filenames:
        filename = os.path.join(file_path, filename)
        os.remove(filename)
        print("remove success: " + filename)


# 2 根据文件路径删除文件
def del_file_by_path(file_path):
    try:
        os.remove(file_path)
        print("remove success: " + file_path)
    except FileNotFoundError as fnfe:
        print(fnfe)


# 3 根据txt中文件路径删除文件
def del_files_by_txt(txt_path):
    txt = open(txt_path)
    for file_path in txt:
        try:
            file_path = file_path.replace('\n', '')
            del_file_by_path(file_path)
            print("remove success: " + file_path)
        except Exception as e:
            print(e)
            continue


if __name__ == '__main__':
    path = r'X:\ai\speech\speech_data'
    flag = 2
    if 1 == flag:
        del_dir(path)
    if 2 == flag:
        del_file_by_path(path)
    if 3 == flag:
        del_files_by_txt(path)
